package com.PVZ.event;

import com.PVZ.engine.Cleaner;
import com.PVZ.model.Entity;
import com.PVZ.model.emuns.AnimeType;
import com.PVZ.model.emuns.EventType;
import com.PVZ.model.interfaces.EventListener;
import com.PVZ.model.plant.CherryBomb;
import com.PVZ.model.plant.Plant;
import com.PVZ.model.zombie.Zombie;
import com.PVZ.utils.Util;

import java.awt.*;

/**
 * Created by @Author: kabuda on @Date: 2021/5/24 20:05
 */
public class DeadEventListener implements EventListener {

    @Override
    public void eventHandler(Event event) {
        if(event.getEventType()== EventType.Dead){
            Entity entity = ((DeadEvent) event).deadEntity;

            if(entity.health<=0&&entity.getIsAlive()==Entity.ALIVE){
                if(entity instanceof Zombie){
                    entity.setCurSpeed(0);
                    entity.setCurAnimeType(AnimeType.BREAK);
                }else if(entity instanceof Plant){
                    if(entity instanceof CherryBomb){
                        entity.setCurAnimeType(AnimeType.BREAK);
                    }else{
                        entity.setIsAlive(Entity.DEAD);
                    }
                    if(!(entity instanceof CherryBomb)){
                        Point point = entity.getPoint();
                        Util.getBlockByPoint(point).setHasPlant(false);
                    }

                }
            }
        }

    }
}
